{include file="public/common" /}


<form class="layui-form" id="order_form">
    <div class="layui-form-item">

        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" name="search_" autocomplete="off" class="layui-input" placeholder="搜索用户名或手机号"
                       value="<?php echo isset($param['search_'])?$param['search_']:''; ?>">
            </div>
        </div>

        <div class="layui-inline">
            <button type="submit" class="layui-btn" >筛选</button>
            <!--<a class="layui-btn" name="export" value="1" onclick="export_data()">导出数据</a>-->
        </div>
    </div>
</form>

<div>
    {if condition="isset($list_)"}
        <table class="layui-table" width="900px">
            <thead>
            <tr style="text-align: center;">
                <td>用户名</td>
                <td>电话</td>
                <td>最终登录ip</td>
                <td>最后登录时间</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody>
            {volist name="list_" id="user"}
            <tr style="text-align: center;">
                <td> {$user.user_name}</td>
                <td> {$user.telephone}</td>
                <td> {$user.last_login_ip}</td>
                <td> {$user.last_login_time}</td>
                <td>
                    {if condition="$user.is_seller == 0"}
                    <a class="layui-btn" onclick='set_seller("{$user.id}","set")'> 设置商家 </a>
                    {elseif condition="$user.is_seller == 1"}
                    <a class="layui-btn layui-btn-normal" onclick='set_seller("{$user.id}","unset")'> 取消商家 </a>
                    {/if}
                    {if condition="$user.is_admin == 0"}
                    <a class="layui-btn" onclick='set_admin("{$user.id}","set")'> 设置管理员 </a>
                    {elseif condition="$user.is_admin == 1"}
                    <a class="layui-btn layui-btn-normal" onclick='set_admin("{$user.id}","unset")'> 取消管理员 </a>
                    {/if}
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {$list_->render()}
    {/if}
</div>

<script>
    /**
     * 删除商品
     * @param id
     * @private
     */
    function set_seller(id,set_type) {
        var s = confirm("确认修改商家身份");
        if(s){
            $.ajax({
                url: '{:addon_url("admin://user/set_seller")}' ,
                dataType: "json",
                async: true,
                data: {
                    "user_id": id,
                    "set_type":set_type
                },
                type: "post",
                success: function (res) {
                    if (res.code == 0) {
                        location.reload();
                    }
                    else {
                        layer.alert(res.data, {icon: 5});
                    }
                },
                error: function (xhr, errorText, errorStatus) {
                    alert('fail');
                }
            });
        }
    }
    /**
     * 删除商品
     * @param id
     * @private
     */
    function set_admin(id,set_type) {
        var s = confirm("确认修改管理员身份");
        if(s){
            $.ajax({
                url: '{:addon_url("admin://user/set_admin")}' ,
                dataType: "json",
                async: true,
                data: {
                    "user_id": id,
                    "set_type":set_type
                },
                type: "post",
                success: function (res) {
                    if (res.code == 0) {
                        location.reload();
                    }
                    else {
                        layer.alert(res.data, {icon: 5});
                    }
                },
                error: function (xhr, errorText, errorStatus) {
                    alert('fail');
                }
            });
        }
    }

</script>